package com.example.neusoft.yuejian_12.Fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.yuejian_12.Adapter.MasterVideoAdapter;
import com.example.neusoft.yuejian_12.JavaBean.Master;
import com.example.neusoft.yuejian_12.Model.VModel;
import com.example.neusoft.yuejian_12.R;
import com.example.neusoft.yuejian_12.Service.MasterService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by admin on 2017/10/26.
 */

public class VideoFragment extends Fragment {

    private RecyclerView recyclerView;
    private String id;
    private TextView videoName;
    private ImageView videoPhoto;
    private Master info;
    private View view;
    private List<Master.MvideoEntity> list;
    private Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.activity_videoinfo_fragment,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.rv_video);
        init();
        event();
        return view;

    }




    public void init()
    {
        recyclerView=(RecyclerView)view.findViewById(R.id.rv_video);
        context=getActivity();
    }


    public void event(){
        Intent intent=getActivity().getIntent();
        String id=intent.getStringExtra("id");
        Retrofit retrofit= VModel.getConn();
       MasterService impls=retrofit.create(MasterService.class);
        Call<Master> call=impls.getVideoList(id,"mvideo");
        call.enqueue(new Callback<Master>() {
            @Override
            public void onResponse(Call<Master> call, Response<Master> response) {
                info=response.body();
                list=info.getMvideo();
                MasterVideoAdapter adapter=new MasterVideoAdapter(context,list);
                LinearLayoutManager manager=new LinearLayoutManager(context);
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                recyclerView.setLayoutManager(manager);
            }

            @Override
            public void onFailure(Call<Master> call, Throwable t) {

            }
        });



    }



}

